<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传</title></head>
<body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<!--<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="js/jquery.form.min.js"></script>-->
<!--<form action="/abc/upload" method="post" enctype="multipart/form-data">
    <input type="file" name="file" value="请选择文件">
    <input type="submit" value="上传">
</form>-->

<form enctype="multipart/form-data" style="margin: 50px 500px">
    <div>
        文件：<input type="file" name="file">
        <br/>
        <br/>
        路径：<input type="text" name="path" id = "path" value="/usr/local/metal/">
        <br/>
        <br/>
        密码：<input type="password" name="password" id="password">
        <br/>
        <br/>
        <button type="submit">上传文件</button>
    </div>
</form>

<script>
    $(document).ready(function() {
        $('form').submit(function(event) {
            // 防止默认表单提交行为
            event.preventDefault();

            // 获取文件对象
            var file = $('input[type=file]')[0].files[0];
            if (!file) {
                alert('请选择文件！')
                return;
            }
            var path = $('#path').val();
            var password = $('#password').val();
            // 创建 FormData 对象
            var formData = new FormData();
            formData.append('file', file);
            formData.append('path', path);
            formData.append('password', password);

            // 发送 AJAX 请求
            $.ajax({
                url: '/ai/abc/upload',
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function(response) {
                    alert(response);
                },
                error: function(xhr, status, error) {
                    alert('上传失败：' + error);
                }
            });
        });
    });
</script>
</body>
</html>